import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Label;


public class AjouterPhoto extends Shell {
	private Text chemin;

	/**
	 * Create the shell.
	 * @param display
	 */
	public AjouterPhoto(Display display, final String titre) {
		super(display, SWT.SHELL_TRIM);
		
		Group grpChemin = new Group(this, SWT.NONE);
		grpChemin.setLocation(22, 10);
		grpChemin.setSize(342, 100);
		grpChemin.setText("Chemin");
		
		chemin = new Text(grpChemin, SWT.BORDER);
		chemin.setBounds(10, 32, 212, 21);
		
		Button btnExplorer = new Button(grpChemin, SWT.NONE);
		btnExplorer.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				

					FileDialog leDialogue = new FileDialog(getShell(), SWT.OPEN);
					leDialogue.setText("Sélectionnez un dossier");
					try
					{
						chemin.setText(leDialogue.open());
						
					}//try
					catch (IllegalArgumentException e1) {}//catch
			
		}});
		btnExplorer.setBounds(245, 30, 75, 25);
		btnExplorer.setText("Parcourir\r\n");
		
		Button btnOk = new Button(grpChemin, SWT.NONE);
		
		btnOk.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				if(chemin.getText() != null)
				{
					Album.ajouterPhoto(titre, chemin.getText());
					fermer();
					
				}
					
				
			}
		});
		btnOk.setBounds(147, 59, 75, 25);
		btnOk.setText("Go\r\n");
		
		Label lblTlchargerLimage = new Label(grpChemin, SWT.NONE);
		lblTlchargerLimage.setBounds(20, 64, 118, 15);
		lblTlchargerLimage.setText("Télécharger l'image");
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("Ajouter une photo");
		setSize(399, 160);

	}
	
	protected void fermer() {
		this.dispose();
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
